package com.murong.ai.coder.entity;

import lombok.Data;
import java.util.List;
import jakarta.xml.bind.annotation.*;

@XmlRootElement(name = "project")
@XmlAccessorType(XmlAccessType.FIELD)
@Data
public class GlobalProperties {
    @XmlAttribute(name = "simple-name")
    private String simpleName;
    @XmlAttribute(name = "name")
    private String name;
    @XmlElement(name = "operator")
    private Operator operator;
    @XmlElement(name = "baseUrl")
    private BaseUrl baseUrl;
    @XmlElement(name = "modules")
    private Modules modules;
    @XmlElement(name = "environments")
    private Environments environments;

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Operator {
        @XmlAttribute(name = "name")
        private String name;
        @XmlAttribute(name = "password")
        private String password;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class BaseUrl {
        @XmlAttribute(name = "path")
        private String path;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Modules {
        @XmlElement(name = "module-web")
        private ModuleWeb moduleWeb;
        @XmlElement(name = "module-api")
        private ModuleApi moduleApi;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class ModuleWeb {
        @XmlElement(name = "class-path")
        private ClassPath classPath;
        @XmlElement(name = "resources")
        private Resources resources;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class ModuleApi {
        @XmlElement(name = "class-path")
        private ClassPath classPath;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class ClassPath {
        @XmlAttribute(name = "path")
        private String path;
        @XmlElement(name = "transaction-action")
        private TransactionPath transactionAction;
        @XmlElement(name = "transaction-controller")
        private TransactionPath transactionController;
        @XmlElement(name = "domain")
        private TransactionPath domain;
        @XmlElement(name = "table-entity")
        private TransactionPath tableEntity;
        @XmlElement(name = "table-mapper")
        private TransactionPath tableMapper;
        @XmlElement(name = "transaction-request")
        private TransactionPath transactionRequest;
        @XmlElement(name = "transaction-response")
        private TransactionPath transactionResponse;
        @XmlElement(name = "transaction-interface")
        private TransactionPath transactionInterface;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class TransactionPath {
        @XmlAttribute(name = "path")
        private String path;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Resources {
        @XmlAttribute(name = "path")
        private String path;
        @XmlElement(name = "table-mapper-xml")
        private TableMapperXml tableMapperXml;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class TableMapperXml {
        @XmlAttribute(name = "path")
        private String path;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Environments {
        @XmlAttribute(name = "global_path")
        private String globalPath;
        @XmlElement(name = "env")
        private List<Env> envList;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Env {
        @XmlAttribute(name = "name")
        private String name;
        @XmlElement(name = "properties")
        private Properties properties;
        @XmlElement(name = "datasource")
        private Datasource datasource;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Properties {
        @XmlAttribute(name = "path")
        private String path;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Datasource {
        @XmlElement(name = "url")
        private String url;
        @XmlElement(name = "username")
        private String username;
        @XmlElement(name = "password")
        private String password;
        @XmlElement(name = "driverClassName")
        private String driverClassName;
        @XmlElement(name = "initialSize")
        private Integer initialSize;

        public DbConfig toDbConfig(){
            DbConfig dbConfig = new DbConfig(this.driverClassName,this.url, this.username, this.password);
            return dbConfig;
        }
    }
} 